package org.smarthings.coap;

import java.util.Properties;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.smarthings.Client;
import org.smarthings.Factory;
import org.smarthings.Server;
import org.smarthings.Utils;

@Component
@Service(Factory.class)
public class CoapFactory implements Factory {
	public static final String PROTOCOL = "COAP";
	private String host;
	private int port;

	public CoapFactory() {
		Properties config = Utils.getConfiguration(this, PROTOCOL.toLowerCase() + ".properties");
		host = config.getProperty("host", "localhost");
		port = Integer.valueOf(config.getProperty("port", "1313"));
	}

	public Server startNewServer() {
		Server server = new CoapServerImpl();
		server.start(host, port);
		return server;
	}

	public Client startNewClient() {
		Client client = new CoapClientImpl();
		client.start(host, port);
		return client;
	}

	public String getProtocol() {
		return PROTOCOL;
	}
}
